package commons.reflect.examples;

public class ArrayAlg {
    public static <T extends Comparable> Pair<T> minmax(T[] a) {
        if (a == null || a.length == 0) return null;
        T min = a[0];
        T max = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i].compareTo(min) < 0) {
                min = a[i];
            }
            if (a[i].compareTo(max) > 0) {
                max = a[i];
            }
        }
        return new Pair<>(min, max);
    }
}
